import * as cc from "cc";
import { GlobalEnum } from "../../Script/GameSpecial/GlobalEnum";
import { EventType } from "../../Script/GameSpecial/GameEventType";
import { UIComponent } from "../../Script/Common/UIComponent";
import GamePlatform from "../../Script/Platform/GamePlatform";
import { GamePlatformType } from "../../Script/Platform/GamePlatformType";
import GlobalData from "../../Script/Common/GlobalData";
// import { NATIVE_AD_STYLE } from "../../Script/Platform/SDK/HeyGameSDK/GlobalData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GameLobby extends UIComponent {
    /**场景/UI类型 */
    public uiType = GlobalEnum.UI.lobby;

    @property(cc.Node)
    protected btnDesk: cc.Node = null;
    @property(cc.Node)
    protected btnNative: cc.Node = null;

    protected initSub() {
        if (GamePlatform.Config.type != GamePlatformType.HeyGameOPPO
            && GamePlatform.Config.type != GamePlatformType.HeyGameVIVO) {
            this.btnDesk.active = false;
            this.btnNative.active = false;
        }
    }

    protected onEvents() {
        this.on(EventType.Common.DirectorEvent.chooseLevelItem, this.onChooseLevelItem, this);
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchBgStart, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchBgEnd, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchBgEnd, this);
    }

    public show() {
        this.node.active = true;
        this.resetAnim();
        this.emit(EventType.Common.AudioEvent.playBGM, GlobalEnum.AudioClip.BGMLobby, true);
        this.emit(EventType.Common.UIEvent.enter, GlobalEnum.UI.playerAssetBar);
    }
    public hide() {
        this.reset();
        this.offEvents();
        super.hide();
    }
    //#region 开始游戏
    protected onBtnStartGame() {
        this.emit(EventType.Common.AudioEvent.playClickBtn);
        this.startGame();
    }
    protected startGame() {
        let lv = this.chosedLevel;
        this.chosedLevel = null;
        this.emit(EventType.Common.DirectorEvent.enterLevel, lv);
    }
    //#endregion

    //#region 选择关卡
    protected chosedLevel: number = null;
    protected onBtnChooseLevel() {
        this.emit(EventType.Common.AudioEvent.playClickBtn);
        this.emit(EventType.Common.UIEvent.enter, GlobalEnum.UI.chooseLevel);
    }
    protected onChooseLevelItem(level) {
        this.chosedLevel = level;
        this.startGame();
        this.emit(EventType.Common.UIEvent.exit, GlobalEnum.UI.chooseLevel);
    }
    //#endregion

    protected onBtnTryMaxCar() {
        this.playClickBtn();
        this.showUI(GlobalEnum.UI.tryMaxCar);
    }

    protected onTouchBgStart() {
        this.emit(EventType.LevelEvent.showMapFast);
    }

    protected onTouchBgEnd() {
        this.emit(EventType.LevelEvent.showMapSlow);
    }

}
